<?php

class Storage {

    protected $_name = '';

    public function getStorage() {
        return fcache('storage', $this->_name);
    }

    public function setStorage($data) {
        return fcache('storage', $this->_name, $data);
    }

    public function setMap($key, $value) {
        $data = fcache('storage', $this->_name);
        if (!$data || !isset($data['map']) || !is_array($data['map'])) {
            $data['map'] = array();
        }
        $data['map'][$key] = $value;
        return fcache('storage', $this->_name, $data);
    }

    public function getMap($key = null) {
        $data = fcache('storage', $this->_name);
        if (!$data || !isset($data['map']) || !is_array($data['map'])) {
            return false;
        }
        $map = $data['map'];
        if ($key) {
            return $map[$key];
        }
        return $map;
    }

    public function setValue($value) {
        $data = fcache('storage', $this->_name);
        if (!$data || !is_array($data)) {
            $data = array();
        }
        $data['value'] = $value;
        return fcache('storage', $this->_name, $data);
    }

    public function getValue() {
        $data = fcache('storage', $this->_name);
        return $data['value'];
    }

}
